home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / gnu / emacs_src_18_58.lha / emacs-18.58 / src / amiga_sysdep.c < prev    next >
C/C++ Source or Header  |  1992-09-23  |  10KB  |  376 lines

  1. /* Interfaces to system-dependent kernel and library entries.
  2. Copyright (C) 1985, 1986, 1987, 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY.  No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing.  Refer to the GNU Emacs General Public
  11. License for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. GNU Emacs, but only under the conditions described in the
  15. GNU Emacs General Public License.   A copy of this license is
  16. supposed to have been given to you along with GNU Emacs so you
  17. can know your rights and responsibilities.  It should be in a
  18. file named COPYING.  Among other things, the copyright notice
  19. and this notice must be preserved on all copies.  */
  20.  
  21. #include <exec/types.h>
  22. #include <dos/dos.h>
  23. #include <dos/dosextens.h>
  24. #include <dos/var.h>
  25. #include <exec/execbase.h>
  26. #include <exec/tasks.h>
  27. #include <utility/tagitem.h>
  28. #include <workbench/startup.h>
  29. #include <workbench/workbench.h>
  30. #include <proto/exec.h>
  31. #include <proto/dos.h>
  32. #include <proto/icon.h>
  33.  
  34. #include <string.h>
  35. #include <ios1.h>
  36. #include <stdio.h>
  37. #include <sys/types.h>
  38. #include <sys/stat.h>
  39. #include <signal.h>
  40. #include <setjmp.h>
  41. #include <unistd.h>
  42. #include <internal/vars.h>
  43.  
  44. #undef LONGBITS
  45. #undef NULL
  46. #include "config.h"
  47. #include "lisp.h"
  48. #include "emacssignal.h"
  49.  
  50. #define min(x,y) ((x) > (y) ? (y) : (x))
  51.  
  52. #include "termhooks.h"
  53. #include "termchar.h"
  54. #include "termopts.h"
  55. #include "dispextern.h"
  56. #include "amiga.h"
  57.  
  58. #define EMACS_TOOL_SIZE 128    /* Room for path to emacs executable */
  59.  
  60. struct Library *IconBase;
  61. extern struct ExecBase *SysBase;
  62.  
  63. int amiga_process_stack_size;
  64.  
  65. int amiga_initialized;
  66. int amiga_create_icons;        /* If true, we create icons when saving files */
  67. enum exit_method amiga_fail_exit = use_xcexit;
  68. int selecting;
  69.  
  70. /* Emacs sysdep routines */
  71. /* --------------------- */
  72.  
  73. set_exclusive_use(int fd) {}
  74.  
  75. /* Suspend the Emacs process; give terminal to its superior.  */
  76. sys_suspend()
  77. {
  78.   /* This could have been iconify, but:
  79.      a) Not good for serial lines.
  80.      b) emacs stays active while iconified */
  81. }
  82.  
  83. char *get_system_name() 
  84. {
  85.   static char sysname[32];
  86.  
  87.   gethostname(sysname, sizeof sysname);
  88.   return sysname;
  89. }
  90.  
  91. /*
  92.  *    flush any pending output
  93.  *      (may flush input as well; it does not matter the way we use it)
  94.  */
  95.  
  96. flush_pending_output (channel)
  97.      int channel;
  98. {
  99. }
  100.  
  101. wait_for_termination (pid)
  102.      int pid;
  103. {
  104.   while (1)
  105.     {
  106.       sigsetmask (sigmask (SIGCHLD));
  107.       if (0 > kill (pid, 0))
  108.         {
  109.       sigsetmask (SIGEMPTYMASK);
  110.       break;
  111.     }
  112.       sigpause (SIGEMPTYMASK);
  113.     }
  114. }
  115.  
  116. /* A few general amiga support routines */
  117. /* ------------------------------------ */
  118.  
  119. char *expand_path(char *path, char *buf, int len)
  120. {
  121.   BPTR dirlock;
  122.   APTR window;
  123.  
  124.   window = _us->pr_WindowPtr;
  125.   _us->pr_WindowPtr = (APTR)-1;
  126.   dirlock = Lock(path, ACCESS_READ);
  127.   _us->pr_WindowPtr = window;
  128.   if (dirlock)            /* Expand lock name */
  129.     {
  130.       if (!NameFromLock(dirlock, buf, len)) buf = 0;
  131.       UnLock(dirlock);
  132.       return buf;
  133.     }
  134.   return 0;
  135. }
  136.  
  137. #undef select
  138. int emacs_select(int nfds, int *rfds, int *wfds, int *efds, struct timeval *timeout)
  139. {
  140.   int ret;
  141.  
  142.   selecting = TRUE;
  143.   ret = select(nfds, rfds, wfds, efds, timeout);
  144.   selecting = FALSE;
  145.   return ret;
  146. }
  147.  
  148. void no_memory(void)
  149. {
  150.   _fail("No memory");
  151. }
  152.  
  153. char *amiga_path(void)
  154. {
  155.   char *path, *pp, name[128];
  156.   int pathsize;
  157.   struct CommandLineInterface *cli;
  158.   BPTR lock;
  159.   long l, *lp, nlen;
  160.  
  161.   pathsize = 128;
  162.   path = (char *)xmalloc(pathsize);
  163.  
  164.   strcpy(path, ".");
  165.   pp = path + 1;
  166.  
  167.   if (!(cli = (struct CommandLineInterface *)((long)_us->pr_CLI << 2)))
  168.     return path;
  169.  
  170.   l = (long)cli->cli_CommandDir;
  171.   while (l) {
  172.     *pp++ = ',';
  173.     l <<= 2;
  174.     lp = (long *)l;
  175.     lock = (BPTR)*(lp + 1);
  176.     NameFromLock(lock, name, 128);
  177.     nlen = strlen(name);
  178.     if (pp + nlen + 5 >= path + pathsize)
  179.       {
  180.     char *newpath;
  181.  
  182.     pathsize = 2 * pathsize + nlen;
  183.     newpath = (char *)xrealloc(path, pathsize);
  184.     pp = newpath + (pp - path);
  185.     path = newpath;
  186.       }
  187.     memcpy(pp, name, nlen);
  188.     pp += nlen;
  189.     l = *lp;
  190.   }
  191.   /* Use of +5 above guarantees that there is enough space for c: */
  192.   strcpy(pp, ",c:");
  193.  
  194.   return path;
  195. }
  196.  
  197. /* Some general amiga commands */
  198. /* --------------------------- */
  199.  
  200. #define emacs_file_icon_width 54
  201. #define emacs_file_icon_height 22
  202. #define emacs_file_icon_num_planes 2
  203.  
  204. static UWORD chip emacs_file_icon_data[2][22][4] = {
  205.     {
  206.         0x0000,0x0000,0x0000,0x0400,0x0000,0x0000,0x0000,0x0c00,
  207.         0x0000,0x0000,0x0000,0x0c00,0x07ff,0xffff,0xffe0,0x0c00,
  208.         0x0400,0x0000,0x0030,0x0c00,0x0400,0x0000,0x0028,0x0c00,
  209.         0x04ff,0xffff,0xfe24,0x0c00,0x0400,0x0000,0x0022,0x0c00,
  210.         0x04ff,0xffff,0xfe3f,0x0c00,0x0400,0x0000,0x0000,0x8c00,
  211.         0x04ff,0xffc0,0x0000,0x8c00,0x0400,0x0000,0x0000,0x8c00,
  212.         0x0400,0x0000,0x0000,0x8c00,0x0400,0x0000,0x0000,0x8c00,
  213.         0x04ff,0xffff,0xfe00,0x8c00,0x0400,0x0000,0x0000,0x8c00,
  214.         0x04ff,0xffff,0xfe00,0x8c00,0x0400,0x0000,0x0000,0x8c00,
  215.         0x07ff,0xffff,0xffff,0x8c00,0x0000,0x0000,0x0000,0x0c00,
  216.         0x0000,0x0000,0x0000,0x0c00,0x7fff,0xffff,0xffff,0xfc00
  217.     },
  218.     {
  219.         0xffff,0xffff,0xffff,0xf800,0x8000,0x0000,0x0000,0x0000,
  220.         0x8000,0x0000,0x0000,0x0000,0x8000,0x0000,0x0000,0x0000,
  221.         0x83ff,0xffff,0xffc0,0x0000,0x83ff,0xffff,0xffd0,0x0000,
  222.         0x8300,0x0000,0x01d8,0x0000,0x83ff,0xffff,0xffdc,0x0000,
  223.         0x8300,0x0000,0x01c0,0x0000,0x83ff,0xffff,0xffff,0x0000,
  224.         0x8300,0x003f,0xffff,0x0000,0x83ff,0xffff,0xffff,0x0000,
  225.         0x83ff,0xffff,0xffff,0x0000,0x83ff,0xffff,0xffff,0x0000,
  226.         0x8300,0x0000,0x01ff,0x0000,0x83ff,0xffff,0xffff,0x0000,
  227.         0x8300,0x0000,0x01ff,0x0000,0x83ff,0xffff,0xffff,0x0000,
  228.         0x8000,0x0000,0x0000,0x0000,0x8000,0x0000,0x0000,0x0000,
  229.         0x8000,0x0000,0x0000,0x0000,0x8000,0x0000,0x0000,0x0000
  230.     },
  231. };
  232. struct Image far emacs_file_icon_image = {
  233.   0, 0,
  234.   emacs_file_icon_width, emacs_file_icon_height, emacs_file_icon_num_planes,
  235.   (UWORD *)emacs_file_icon_data,
  236.   3, 0,
  237.   0
  238. };
  239.  
  240. static char *far emacs_file_tooltypes[] = {
  241.   "FILETYPE=TEXT",
  242.   0
  243. };
  244.  
  245. static char far emacs_tool[EMACS_TOOL_SIZE];
  246.  
  247. static struct DiskObject far emacs_file_icon_object = {
  248.   WB_DISKMAGIC, WB_DISKVERSION,
  249.   { 0, 0, 0, emacs_file_icon_width, emacs_file_icon_height,
  250.     GFLG_GADGIMAGE | GADGBACKFILL, GACT_IMMEDIATE | GACT_RELVERIFY, GTYP_BOOLGADGET,
  251.     (APTR)&emacs_file_icon_image },
  252.   WBPROJECT, emacs_tool, emacs_file_tooltypes,
  253.   NO_ICON_POSITION, NO_ICON_POSITION,
  254.   0, 0,
  255.   40000                /* Stack size for emacs */
  256. };
  257.  
  258. DEFUN ("amiga-put-icon", Famiga_put_icon, Samiga_put_icon, 2, 2, 0,
  259.        "Create an icon for FILE.\n\
  260. If FORCE is non-nil create it unconditionally, otherwise only if one doesn't exist.\n\
  261. Returns t if an icon was created, nil otherwise.")
  262.      (file, force)
  263. Lisp_Object file, force;
  264. {
  265.   char *fname;
  266.   struct DiskObject *obj;
  267.  
  268.   CHECK_STRING(file, 0);
  269.   fname = XSTRING(file)->data;
  270.  
  271.   if (NULL (force) && (obj = GetDiskObject(fname)))
  272.     {
  273.       /* Icon exists, don't overwrite */
  274.       FreeDiskObject(obj);
  275.       return Qnil;
  276.     }
  277.   emacs_file_icon_object.do_StackSize = _stack_size;
  278.   if (PutDiskObject(fname, &emacs_file_icon_object)) return Qt;
  279.   error("Icon for %s couldn't be created", fname);
  280. }
  281.  
  282. /* Amiga initialisation routines */
  283. /* ----------------------------- */
  284.  
  285. syms_of_amiga ()
  286. {
  287.   DEFVAR_BOOL("amiga-initialized", &amiga_initialized, "");
  288.   DEFVAR_INT("amiga-malloc-bytes-used", &malloc_bytes_used,
  289.          "Number of malloc bytes used when emacs was dumped");
  290.   DEFVAR_BOOL("amiga-create-icons", &amiga_create_icons,
  291.          "If non-nil, create icons when saving files.");
  292.   defsubr(&Samiga_put_icon);
  293.   amiga_process_stack_size = 0;
  294.   DEFVAR_INT("amiga-process-stack-size", &amiga_process_stack_size,
  295.      "Size of stack for called processes. 0 means same size as emacs stack.");
  296.   syms_of_amiga_tty();
  297.   syms_of_amiga_menu();
  298.   syms_of_amiga_clipboard();
  299. }
  300.  
  301. static void amiga_early_init(int *_argc, char ***_argv)
  302. {
  303.   int argc = *_argc;
  304.   char **argv = *_argv;
  305.  
  306.   if (argc > 2 && !strcmp(argv[1], "-pure"))
  307.     {
  308.       puresize = atoi(argv[2]);
  309.       argc -= 2; argv += 2;
  310.     }
  311.   if (argc > 2 && !strcmp(argv[1], "-malloc"))
  312.     {
  313.       malloc_hunk_size = atoi(argv[2]);
  314.       argc -= 2; argv += 2;
  315.     }
  316.   if (argc > 2 && !strcmp(argv[1], "-prealloc"))
  317.     {
  318.       pre_alloc = atoi(argv[2]);
  319.       argc -= 2; argv += 2;
  320.     }
  321.   /* Handle the -dev switch, which specifies device & unit to use as terminal */
  322.   if (argc > 3 && !strcmp (argv[1], "-dev"))
  323.     {
  324.       extern char *far serial_device;
  325.       extern long serial_unit;
  326.  
  327.       serial_device = argv[2];
  328.       serial_unit = atoi(argv[3]);
  329.       fprintf (stderr, "Using %s (unit %d)\n", serial_device ,serial_unit);
  330.       inhibit_window_system = 1; /* -dev => -nw */
  331.       argc -= 3; argv += 3;
  332.     }
  333.   /* Patch real argc, argv to hide arguments we used */
  334.   argv[0] = (*_argv)[0];
  335.   *_argv = argv;
  336.   *_argc = argc;
  337.  
  338.   expand_path(argv[0], emacs_tool, EMACS_TOOL_SIZE);
  339. }
  340.  
  341. void cleanup_amiga(void)
  342. {
  343.   cleanup_clipboard();
  344.   cleanup_amiga_tty();
  345.   if (IconBase) CloseLibrary(IconBase);
  346. }
  347.  
  348. void amiga_undump_reinit(void)
  349. /* Post-undump initialisation */
  350. {
  351.   extern struct WBStartup *WBenchMsg;
  352.  
  353.   emacs_malloc_init();
  354.   early_amiga_tty();
  355.   early_clipboard();
  356.  
  357.   if (!onexit(cleanup_amiga)) _fail("Internal problem with onexit");
  358.  
  359.   make_environ();
  360.   IconBase = OpenLibrary("icon.library", 0);
  361.   if (!IconBase) _fail("Need icon.library");
  362.   amiga_create_icons = WBenchMsg != 0;
  363.  
  364.   init_amiga_tty(); init_clipboard();
  365. }
  366.  
  367. #undef main
  368. main(int argc, char **argv)
  369. /* Effect: Call emacs_main after doing some early amiga initialisation for emacs.
  370. */
  371. {
  372.   /* This initialisation may steal some command line options */
  373.   amiga_early_init(&argc, &argv);
  374.   emacs_main(argc, argv);
  375. }
  376.